<?php
/**
 * 地区管理
 * 
 * @author  Lee<a605333742@gmail.com>
 * @time    2016-07-30
 */
namespace Admin\Controller;

class RegionController extends CommonController{
    /*
     * 构造函数
     *
     * @return  #
     */
    public function _initialize(){       
        parent::_initialize();
        $this->db   =new \Model\RegionModel();       
    }
    
    /*
     * 地区列表
     * 
     * @return #
     */
    public function index(){
        if(I("request.name")){
            $map['name']=I("request.name");
        }
        $map=$this->_search("Region");
        $regionList =$this->_list($this->db,$map);
        $this->assign("regList",$regionList);
        $this->display();
    }
    
    /*
     * 新增地区
     * 
     * @return #
     */
    public function show(){
        if(I("request.id")){
            $regionInfo =$this->db->find(I("request.id",'',"int"));
            $this->assign("reInfo",$regionInfo);
        }
        $this->display();
    }
        
    /*
     *编辑地区
     * 
     * @return # 
     */
    public function edit(){
        if(I("request.name")){
            $map['name']=I("request.name",'','trim');
        }else{
            $this->error("地区名不能为空");
        }
        if(I("request.id")){
            $map['id']  =I("request.id","","int");
        }
        if($this->db->edit($map)){
            $this->success("地区编辑成功");
        }else{
            $this->error("地区编辑失败");
        }        
    }
    
    /*
     * 删除，批量删除地区
     * 
     * @return #
     */
    public function del(){
        $map['id']      =I("request.id");
        if($this->db->del($map)){
            $this->success("地区删除成功");
        }else{
            $this->error("地区删除失败");
        }
    }
}